"""
目前的思路：
    1. 重要与紧急程度的表示：
    正半轴：1 - 5
    负半轴：-5 - -1
    x轴表示重要程度，y轴表示紧急程度

    值得一提的是，真正重要的，往往是重要且不紧急的
"""
# 需要添加方法，完成任务，修改任务内容，添加任务
import pandas as pd

class MissionList:
    def __init__(self, path=r'D:\MissionList\25.11.9-demo\MissionList.csv', read_json=False, read_csv=False):
        if read_json:
            self.list = self.read_json(path)
        elif read_csv:
            self.list = self.read_csv(path)
        else:
            self.list = self.init_list()

    def read_json(self, path):
        pass

    def read_csv(self, path):
        try:
            df = pd.read_csv(path, encoding='utf-8')
            sorted_df = df.sort_values(by=['total', 'importance'], ascending=[False, False])
            return sorted_df
        except Exception as e:
            print(e)

    def save_csv(self, path='MissionList.csv'):
        try:
            self.list.to_csv(path, encoding='utf-8')
        except Exception as e:
            print(e)

    def get_num(self, flag):
        name = '重要性' if flag else '紧急性'
        while True:
            try:
                num = int(input(f'{name}(-5-5):'))
                if num not in range(-5, 6):
                    print('重新输入')
                    continue
                return num
            except Exception as e:
                print(e, '\n重新输入')
                continue

    def init_list(self):
        missions = []
        count = 1
        while True:
            print('任务', count)
            mission = input('任务(0 to stop):')
            if mission == '0':
                break
            currency = self.get_num(0)
            importance = self.get_num(1)
            total = currency + importance
            missions.append({'mission': mission, 'importance': importance, 'currency': currency, 'total': total})
            count += 1
        df = pd.DataFrame(missions)
        sorted_df = df.sort_values(by=['total', 'importance'], ascending=[False, False])
        return sorted_df

    def show(self):
        print(self.list)

    def finish_mission(self):
        try:
            self.show()
            index = int(input('所完成任务的编号'))
            if index not in self.list.index.tolist():
                raise ValueError('编号不存在')
            self.list.drop(index,inplace=True)
            print('任务', index, '已完成')
            self.save_csv()
            return True
        except Exception as e:
            print(e)
            return False
def main():
    # list = MissionList()
    list = MissionList(read_csv=True)
    # list.show()
    # list.save_csv()
    while list.finish_mission():
        pass
if __name__ == '__main__':
    main()